import axios from 'axios';
import qs from 'query-string';

export interface AdminLogId {
    id: number;
}

export interface AdminLogRecord {
    id: number;
    admin_id: number;
    action: string;
    ip: string;
    create_time: string;
    update_time: string;
}

export interface AdminLogListRes {
    list: AdminLogRecord[];
    total: number;
}

export interface AdminLogModel {
    id: number;
    admin_id: number;
    action: string;
    ip: string;
}

export interface AdminLogParams extends Partial<AdminLogRecord> {
    current: number;
    pageSize: number;
}

/**
 * 获取管理员日志列表
 * @param params
 */
export function queryAdminLogList(params: AdminLogParams) {
    return axios.get<AdminLogListRes>('/admin/log/index', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 获取管理员日志详情
 * @param params
 */
export function queryAdminLogOne(params: AdminLogId) {
    return axios.get<AdminLogRecord>('/admin/log/detail', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 删除管理员日志
 * @param id
 */
export function delAdminLog(id: number) {
    return axios.post('/admin/log/delete', { id });
}
